# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)

# 项目信息
project (Demo)

set (Demo_VERSION_MAJOR 11)
set (Demo_VERSION_MINOR 10)


# 加入一个配置头文件，用于处理 CMake 对源码的设置
configure_file (
  "${PROJECT_SOURCE_DIR}/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
  )


  
# 是否使用自己的 MathFunctions 库
option (USE_MYMATH
       "Use provided math implementation" ON)

	   

#定义变量，用-D开头，后面跟字符串，相当于一个宏_VAR，其内容是一个字符串,\"是转义字符，${a}是一个引用变量，用上面的set(a "/home/wsw/test/c++")中的字符串替换
ADD_DEFINITIONS(-D_USE_MYMATH="${USE_MYMATH}")
ADD_DEFINITIONS(-D_Demo_VERSION_MAJOR="${Demo_VERSION_MAJOR}")
ADD_DEFINITIONS(-D_Demo_VERSION_MINOR="${Demo_VERSION_MINOR}")
	   

include_directories ("${PROJECT_SOURCE_DIR}/math")
include_directories (${PROJECT_BINARY_DIR})
add_subdirectory (math)
set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)



# 查找当前目录下的所有源文件
# 并将名称保存到 DIR_SRCS 变量
aux_source_directory(. DIR_SRCS)



# 指定生成目标
add_executable(Demo ${DIR_SRCS})

# 添加链接库
target_link_libraries (Demo  ${EXTRA_LIBS})

install (TARGETS Demo DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/config.h"
         DESTINATION include)
		 
# 启用测试
enable_testing()

# 定义一个宏，用来简化测试工作
macro (do_test arg1 arg2 result)
  add_test (test_${arg1}_${arg2} Demo ${arg1} ${arg2})
  set_tests_properties (test_${arg1}_${arg2}
    PROPERTIES PASS_REGULAR_EXPRESSION ${result})
endmacro (do_test)
 
# 使用该宏进行一系列的数据测试
do_test (5 2 "is 25")
do_test (10 5 "is 100000")
do_test (2 10 "is 1024")

# 构建一个 CPack 安装包
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE
  "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set (CPACK_PACKAGE_VERSION_MAJOR "${Demo_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${Demo_VERSION_MINOR}")
include (CPack)